package com.javaee.service.impl;

import com.javaee.dao.activityDao;
import com.javaee.domain.Activity;
import com.javaee.domain.User;
import com.javaee.service.activityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class activityServiceImpl implements activityService {

    @Autowired
    private activityDao activityDao;

    public boolean isnameExist(Activity activity) {
        if(activityDao.isnameExist(activity)>0){
            return true;
        }
        else return false;
    }
    public String add(Activity activity) {
        if (isnameExist(activity)) {
            return "该活动已经存在";}
        else if (activityDao.add(activity) > 0) {
            return "活动添加成功";
        } else {
            // 处理其他可能的失败情况
            return "活动添加失败";
        }
    }

    public Activity query(Integer id) {
                if(isnameExist(activityDao.getById(id))){
                    return activityDao.getById(id);
                }
               else return null;
    }

    @Override
    public List<Activity> getAll() {
        return activityDao.showdata();
    }
}
